package com.hurui.xiaoming.weight;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hurui.xiaoming.R;
import com.hurui.xiaoming.utils.DisplayParams;
import com.hurui.xiaoming.utils.DisplayUtil;

/**
 * Created by hurui on 2017/7/16.
 */

public class MoneyTextView extends LinearLayout {

    //大小字号
    float big , smart;
    TextView big_tv , small_tv;

    public MoneyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray a = context.obtainStyledAttributes(attrs , R.styleable.MoneyTextView);
        DisplayParams displayParams = DisplayParams.getInstance(context);
        big = a.getDimension(R.styleable.MoneyTextView_big_font , 50);
        smart = a.getDimension(R.styleable.MoneyTextView_small_font , 50);

        big = DisplayUtil.px2dip(big , displayParams.fontScale);
        smart = DisplayUtil.px2dip(smart , displayParams.fontScale);
        a.recycle();
        initView();
    }

    private void initView() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.money_textview_layout , null);
        big_tv = (TextView) view.findViewById(R.id.money_num1);
        small_tv = (TextView) view.findViewById(R.id.money_num2);
        big_tv.setTextSize(big);
        small_tv.setTextSize(smart);
        addView(view);
    }

    public MoneyTextView(Context context) {
        this(context , null);
    }

    public void setText(String str){
        String[] s = str.split("\\.");
        if(s.length < 2){
            big_tv.setText(str);
            small_tv.setText(".00");
        }else{
            big_tv.setText(s[0]);
            small_tv.setText("."+s[1]);
        }
    }
}
